﻿Test test = new Test(10);
for (Int32 i = 0; i < 10; i++)
{
    test[i] =(i % 2 == 0);
}
for (Int32 i = 0; i < 10; i++)
{
    Console.WriteLine(i + (test[i]?"true":"false"));

}






class Test
{
    private Byte[] _byte;
    private Int32 _num;
   
   
    public Test(Int32 num)
    {
        if (num <= 0)
        {
            throw new ArgumentOutOfRangeException("参数要大于0");
        }
        _num = num;
        _byte = new Byte[(num + 7) / 8];
    }
 

    public Boolean this[Int32 bit]
    {
        get
        {
            if (bit < 0 || bit >= _num)
            {
                throw new ArgumentOutOfRangeException("bit");
            }
            return (_byte[bit / 8] & (1 << (bit % 8))) != 0;
        }

        set
        {
            if (bit < 0 || bit >= _num)
            {
                throw new ArgumentOutOfRangeException("bit",bit.ToString());
            }
            if (value)
            {
                _byte[bit / 8] = (byte)(_byte[bit / 8] | (1 << (bit % 8)));

            }
            else
            {
                _byte[bit / 8] = (byte)(_byte[bit / 8] & ~(1 << (bit % 8)));
            }
        }
    }

   

}
